/*
# This file is Copyright 2011, Jesús Leganés Combarro "Piranna".
#
# Based on code copyright 2006, 2007, 2009 Dean Hall.
#
# The multiboot code is based on the multiboot specification example code,
# Copyright (C) 1999  Free Software Foundation, Inc. with GPL license.
#
# This file is part of the Python-on-a-Chip program.
# Python-on-a-Chip is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
# 
# Python-on-a-Chip is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
# is seen in the file COPYING up one directory from this.
*/


#include "multiboot.h"

#include "pm.h"

#define HEAP_SIZE 0x2000
//#define HEAP_SIZE 0x4000

extern unsigned char usrlib_img[];


/* Check if the bit BIT in FLAGS is set. */
#define CHECK_FLAG(flags,bit)	((flags) & (1 << (bit)))


int cmain(unsigned long magic, unsigned long addr)
{
    uint8_t heap[HEAP_SIZE];
    PmReturn_t retval;

    /* Am I booted by a Multiboot-compliant boot loader? */
    if(magic != MULTIBOOT_BOOTLOADER_MAGIC)
        return (int)PM_RET_ERR;

//    /* Set MBI to the address of the Multiboot information structure. */
//    multiboot_info_t* mbi = (multiboot_info_t*)addr;

    /* Launch PyMite Python virtual machine */
    retval = pm_init(heap, HEAP_SIZE, MEMSPACE_PROG, usrlib_img);
    PM_RETURN_IF_ERROR(retval);

    retval = pm_run((uint8_t*)"main");

    return (int)retval;
}
